<?php
if (!defined('ROOT_PATH')) die('No direct access.');
	view_header_top();
	//----------------------------------------------------------------
	$title = "Realita - Beranda";
	$content = "Realita UMKM";
	$url = HOME_URL;
	$image = IMAGE_URL."300x240.gif";	//profpic orangnya / tokonya
	$desc = "Beranda sistem RealiTA UMKM";
	$auth = "RealiTA";
	$qwords = "utama, marketplace, umkm";
	//----------------------
	echo "<title>$title</title>";
	//<!--META DATA Open Graph-->
	echo "<meta property=\"og:title\" content=\"$title\"/>";
	echo "<meta property=\"og:type\" content=\"$content\"/>";
	echo "<meta property=\"og:url\" content=\"$url\"/>";
	echo "<meta property=\"og:image\" content=\"$image\"/>";
	echo "<meta property=\"og:site_name\" content=\"RealiTA UMKM\"/>";
	echo "<meta property=\"og:description\" content=\"$desc\" />";
	//<!--META DATA FB-->
	echo "<meta property=\"fb:app_id\" content=\"147346958657510\" />";
	//<!--META DATA-->
	echo "<meta name=\"author\" content=\"$auth\" />";
	echo "<meta name=\"keywords\" content=\"$qwords\" />";
	echo "<meta name=\"description\" content=\"$desc\" />";
	echo "<meta name=\"robots\" content=\"ALL\" />";
	echo "<meta charset=\"UTF-8\" />";
	//----------------------------------------------------------------
	?>
	<style>

	</style>
	<script>

	</script>
	<?php
	view_header_bottom();
	$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
	if (strpos($url,'?')>0) $url = substr($url,0,strpos($url,'?'));
?>
<?php
/*<a href="#" 
  onclick="
    window.open(
      'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(location.href), 
      'facebook-share-dialog', 
      'width=626,height=436'); 
    return false;">
  Share on Facebook
</a><br />
<div class="fb-activity" data-app-id="Display all actions associated with this app ID" data-site="http://cafe.idebeda.com/" data-action="likes, recommends" data-width="The pixel width of the plugin. Defaults to 300px" data-height="The pixel height of the plugin. Defaults to 300px" data-colorscheme="light" data-header="true"></div><br />
<!--FB site ACTIVITY-->

<div class="fb-facepile" data-app-id="Display people who logged into a site using this app" data-href="http://cafe.idebeda.com/ronda-sebagai-programmer/" data-action="likes,recommends" data-width="The pixel width of the plugin" data-height="The pixel height of the plugin" data-max-rows="1" data-colorscheme="light" data-size="small" data-show-count="true"></div><br />
<!--FB Facepile Like-->

<div class="fb-like" data-href="http://cafe.idebeda.com/ronda-sebagai-programmer/" data-width="The pixel width of the plugin" data-height="The pixel height of the plugin" data-colorscheme="light" data-layout="box_count" data-action="like" data-show-faces="true" data-send="false"></div><br />
<!--FB Like Button-->

<div class="fb-like-box" data-href="http://www.facebook.com/idebeda.piranti.cerdas" data-width="300" data-colorscheme="light" data-show-faces="true" data-header="true" data-stream="true" data-show-border="true"></div><br />
<!--FB Page Like-->

<div class="fb-comments" data-href="<?php echo $url?>" data-colorscheme="The color scheme used in the plugin" data-numposts="3" data-width="The pixel width of the plugin"></div>
<!--FB Comment-->

<div class="fb-send" data-href="http://developers.facebook.com/docs/plugins/" data-width="The pixel width of the plugin" data-height="The pixel height of the plugin" data-colorscheme="light"></div>
<!--FB Send-->

*/ ?>
<?php
	if (isset($_SESSION['logged'])){
		echo "it works<br />";
		try {
	        /* ---------POST LINK FB
	        $msg = "Kami ada produk baru nih";
		    $caption = "Sebuah judul";
		    $desc = "Sebuah penjelasan singkat";
		    $url = "www.idebeda.com";
	         $ret = $facebook->api('/me/feed', 'POST',
	                                    array(
	                                      'message' => $msg,
											'link' => $url,
											'caption' => $caption,
											'description' => $desc
	                                 ));
	                                // */
	        /* -------------- POST group FB
		    $msg = "Kami ada produk baru nih";
		    $caption = "Sebuah judul";
		    $desc = "Sebuah penjelasan singkat";
		    $url = "www.idebeda.com";
			$ret = $facebook->api('/1413027688909258/feed', 'POST',
	                                    array(
											'message' => $msg,
											'link' => $url,
											'caption' => $caption,
											'description' => $desc
	                                 ));
			// */
			/* ---------CHECK group FB
			$cgroup = "SELECT uid FROM group_member WHERE gid = 1413027688909258 AND uid = me()";
			$ret = $facebook->api( array(
                         'method' => 'fql.query',
                         'query' => $cgroup
                     ));
			if (count($ret)<1) {
				echo "belum gabung";
			}
			// */
	         /* ---------------------MUTUAL Friends                        
	          $mutfriend = "SELECT name,mutual_friend_count,uid FROM user WHERE uid IN (SELECT uid2 FROM friend where uid1='1635634213' and uid2 in (SELECT uid2 FROM friend where uid1=me()))";  
	          //$flist = "SELECT name,uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";
			$ret = $facebook->api( array(
                         'method' => 'fql.query',
                         'query' => $mutfriend,
                     ));
             $ret = $facebook->api('/me/mutualfriends/1635634213', 'GET',
									array(
									  'fields' => 'id,name'
								 ));
			 // */
			 /*---------------------CHECK Friends 
			 $uid = "1365634213";                       
             $ret = $facebook->api("/me/friends/$uid", 'GET',
									array(
								 ));
			echo count($ret['data'])."<br />";
			if (count($ret['data'])<1) {
				echo "<form action='https://www.facebook.com/dialog/friends/' target='_blank'>
						<input type='hidden' name='id' value='$uid' />
						<input type='hidden' name='app_id' value='147346958657510' />
						<input type='hidden' name='redirect_uri' value='http://localhost/realita/close' />
						<input type='submit' value='Connect with me on Facebook!' />
					</form>";
			}
			//kalau count==0 belum friend, kalau 1 sudah friend
			// */	
			/*---------------------GET Friends using App
			$query = "SELECT uid, name, pic_square FROM user WHERE is_app_user=1 AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";
			$ret = $facebook->api( array(
                         'method' => 'fql.query',
                         'query' => $query,
                     ));
             // */			 
			/* ---------LIKE a link FB with open graph
	         $ret = $facebook->api('/me/og.likes', 'POST',
	                                    array(
	                                      'object' => 'http://www.ans4175.com',
	                                      'no_feed_story' => 'false',
	                                      'fb:explicitly_shared' => 'true'
	                                 ));
	          $ret = $facebook->api("/10200663033047316", 'GET',
									array(
								 ));
		    //                   */
		    /* ---------POST comment on FB
		     $msg = "Situ okay";
	         $ret = $facebook->api('/1505350263_10200664516724407/comments', 'POST',
	                                    array(
	                                      'message' => $msg,
	                                 ));
	                                // */
			/* ---------GET Comment FB
			$cgroup = "SELECT fromid, time, text FROM comment WHERE object_id = 10200664516724407";
			$ret = $facebook->api( array(
                         'method' => 'fql.query',
                         'query' => $cgroup
                     ));
	         $ret = $facebook->api('/1505350263_10200664516724407/comments', 'GET',
	                                    array(
	                                 ));
			var_dump($ret['data']);
			// */
			/* ---------POST comment on site
		     $msg = "Situ okay";
	         $ret = $facebook->api('/1505350263_10200664516724407/comments', 'POST',
	                                    array(
	                                      'message' => $msg,
	                                 ));
	                                // */
			var_dump($ret);
		} catch(FacebookApiException $e) {
	        // If the user is logged out, you can have a 
	        // user ID even though the access token is invalid.
	        // In this case, we'll get an exception, so we'll
	        // just ask the user to login again here.
	        $login_url = $facebook->getLoginUrl( array(
	                       'scope' => 'publish_stream'
	                       )); 
	        echo 'Please <a href="' . $login_url . '">login.</a>';
	        var_dump($e->getMessage());
	        error_log($e->getType());
	        error_log($e->getMessage());
      }
	}	
	view_footer();
?>
